﻿using System;
using System.Collections.Generic;
using ExamPlat.Models;
using System.Data;
using ExamPlat.DAL;

namespace ExamPlat.Repositories
{
    public class RoleInfoRepository : IRoleInfoRepository
    {
        /// <summary>
        /// 查询角色信息
        /// </summary>
        /// <returns></returns>
        public IList<RoleInfo> GetRoleInfos()
        {
            try
            {
                string sql = "select * from RoleInfo order by RoleName desc ";
                DataSet ds = SqlHelper.ExecuteQuery(sql);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    IList<RoleInfo> result = new List<RoleInfo>();
                    DataTable dt = ds.Tables[0];
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        RoleInfo tmpResult = new RoleInfo();
                        tmpResult.ID = (int)dt.Rows[i]["ID"];
                        tmpResult.RoleName = dt.Rows[i]["RoleName"].ToString();
                        result.Add(tmpResult);
                    }
                    return result;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}